//
//  ApplyInfoViewController.m
//  OneCreditTreasure
//
//  Created by iOS Tedu on 16/8/29.
//
//

#import "ApplyInfoViewController.h"
#import "ApplyInfoHeaderView.h"
#import "ApplyInfoTableViewCell.h"
#import "SuccessCommitViewController.h"

@interface ApplyInfoViewController () <UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) UIButton *confirmBtn;

@property (nonatomic, strong) NSArray<NSArray *> *dataArr;
@property (nonatomic, strong) NSArray<NSArray *> *demoDataArr;
@end

@implementation ApplyInfoViewController
#pragma mark - UITableView dataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return section == 0 ? 3 : 2;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ApplyInfoTableViewCell *Cell = [tableView dequeueReusableCellWithIdentifier:@"detailCell" forIndexPath:indexPath];
    
    Cell.textLabel.text = self.dataArr[indexPath.section][indexPath.row];
    Cell.textLabel.font = [UIFont systemFontOfSize:16 * AUTO_WIDTH];
    Cell.rightInfoLB.text = self.demoDataArr[indexPath.section][indexPath.row];
    
    return Cell;
}

#pragma mark - UITableView delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return section == 0 ? 0 : 10 * AUTO_WIDTH;
}

#pragma mark - 生命周期 life cycle
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self tableView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (instancetype)init {
    if (self = [super init]) {
        [self tableView];
        self.title = @"申请";
    }
    return self;
}

#pragma mark - 方法 methods
- (void)confirmCommittingInfo:sender {
    SuccessCommitViewController *vc = [SuccessCommitViewController new];
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark - 懒加载 lazy loading
- (UITableView *)tableView {
    if(_tableView == nil) {
        _tableView = [[UITableView alloc] init];
        [self.view addSubview:_tableView];
        [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.top.equalTo(0);
            make.bottom.equalTo(self.confirmBtn.mas_top).equalTo(0);
        }];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        
        [_tableView registerClass:[ApplyInfoTableViewCell class] forCellReuseIdentifier:@"detailCell"];
        
        _tableView.tableHeaderView = [[ApplyInfoHeaderView alloc] initWithFrame:CGRectMake(0, 0, kScreenW, 90 * AUTO_WIDTH)];
        _tableView.tableFooterView = [UIView new];
    }
    return _tableView;
}

- (NSArray<NSArray *> *)dataArr {
    if(_dataArr == nil) {
        _dataArr = @[@[@"贷款额度 (元)",@"月利率",@"总利息 (元)"],@[@"姓名",@"手机号"]];
    }
    return _dataArr;
}

- (NSArray<NSArray *> *)demoDataArr {
    if(_demoDataArr == nil) {
        _demoDataArr = @[@[@"522900",@"1.23%",@"127997.50"],@[@"小李",@"1234567890"]];
    }
    return _demoDataArr;
}

- (UIButton *)confirmBtn {
    if(_confirmBtn == nil) {
        _confirmBtn = [UIButton buttonWithType:UIButtonTypeSystem];
        [self.view addSubview:_confirmBtn];
        [_confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.bottom.right.equalTo(0);
            make.height.equalTo(44);
        }];
        [_confirmBtn setTitle:@"确认提交" forState:UIControlStateNormal];
        _confirmBtn.backgroundColor = kRGBA(0, 0, 0, 0.8);
        [_confirmBtn addTarget:self action:@selector(confirmCommittingInfo:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _confirmBtn;
}

@end
